﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SharpShare.Storage;

namespace SharpShare.Afp.Protocol.Handlers {
    internal class AfpGetFileDirectoryParamsRequestHandler : IAfpRequestHandler {
        #region IAfpRequestHandler Members

        public byte CommandCode {
            get { return 34; }
        }

        public AfpResultCode Process(IAfpSession session, DsiHeader dsiHeader, AfpStream requestStream, AfpStream responseStream) {
            requestStream.ReadPadding();

            ushort volumeId = requestStream.ReadUInt16();
            uint directoryID = requestStream.ReadUInt32();
            AfpFileDirectoryBitmap fileBitmap = requestStream.ReadEnum<AfpFileDirectoryBitmap>();
            AfpFileDirectoryBitmap directoryBitmap = requestStream.ReadEnum<AfpFileDirectoryBitmap>();
            IAfpVolume volume;
            IStorageItem item = requestStream.ReadPathAndFind(session, volumeId, directoryID, out volume).DemandExists();

            responseStream.WriteEnum(fileBitmap);
            responseStream.WriteEnum(directoryBitmap);

            AfpResultCode result = item.WriteStorageItemParameters(responseStream, volume, fileBitmap, directoryBitmap);

            return result;
        }

        #endregion
    }
}
